package at.jku.se.fastsell.data;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.owlike.genson.annotation.Creator;
import com.owlike.genson.annotation.JsonProperty;

public class Auction implements Serializable {

	private static final long serialVersionUID = 3431195570263109507L;

	private long auctionID;
	
	private String title, description, highestBidder;
	public double curPrice;
	private String seller;
	private long start, end;
	private int bidCount;
	
	// ----------------------------------------------------------------------------------
	
	@Creator
	public Auction(@JsonProperty("auctionID") long auctionID, 
			@JsonProperty("title") String title,
			@JsonProperty("description") String description,
			@JsonProperty("highestBidder") String highestBidder,
			@JsonProperty("curPrice") double curPrice,
			@JsonProperty("seller") String seller,
			@JsonProperty("start") long start,
			@JsonProperty("end") long end,
			@JsonProperty("bidCount") int bidCount) {
		
		this.auctionID = auctionID;
		this.title = title;
		this.description = description;
		this.highestBidder = highestBidder;
		this.curPrice = curPrice;
		this.seller = seller;
		this.start = start;
		this.end = end;
		this.bidCount = bidCount;		
	}
	
	// ----------------------------------------------------------------------------------
		
	public boolean isActive() {
		if (new Date().getTime() > end) {
			return false;
		}
		return true;
	}
	
	public String getRemainingTime() {
		if (isActive()) {
			long diff = end - new Date().getTime();
			
			long diffSeconds = diff / 1000 % 60;
			long diffMinutes = diff / (60 * 1000) % 60;
			long diffHours = diff / (60 * 60 * 1000) % 24;
			long diffDays = diff / (24 * 60 * 60 * 1000);
			
			return (diffDays + "d " + diffHours + "h " + diffMinutes + "m " + diffSeconds + "s");
		}
		return "ended";
	}
		
	public boolean hasBids() {
		if (bidCount > 0) {
			return true;
		}
		return false;
	}
	
	// ----------------------------------------------------------------------------------
	
	public long getAuctionID() {
		return auctionID;
	}
	public String getTitle() {
		return title;
	}
	public String getDescription() {
		return description;
	}
	public String getSeller() {
		return seller;
	}
	public double getCurPrice() {
		return curPrice;
	}
	public long getStart() {
		return start;
	}
	public long getEnd() {
		return end;
	}
	public int getBidCount() {
		return bidCount;
	}
	public String getHighestBidder() {
		return highestBidder;
	}


}
